Preserve unknown enum values instead of silently dropping them#1485
Open
phongl7 wants to merge 1 commit into
Open
Preserve unknown enum values instead of silently dropping them#1485phongl7 wants to merge 1 commit into
phongl7 wants to merge 1 commit into
Conversation
When the server returns an enum value this SDK version doesn't recognize, _enum coerced it to None and _repeated_enum skipped it. Combined with as_dict() omitting None fields, the value disappeared entirely (silent data loss). For example, warehouses.list() drops warehouse_type for the REAL_TIME warehouse type, which isn't in EndpointInfoWarehouseType. Preserve unknown values via an UnknownEnumValue wrapper that exposes .value so the data round-trips through as_dict(), while staying distinguishable from a known enum member. Known values and absent/empty fields are unchanged.
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When the server returns an enum value this SDK version doesn't recognize, the SDK
currently coerces it to
None(_enum) or skips it (_repeated_enum). Combined withas_dict()omittingNonefields, this means the value disappears entirely — silentdata loss.
This PR preserves unknown enum values via a small
UnknownEnumValuewrapper thatexposes
.value, so the data round-trips throughas_dict()while staying clearlydistinguishable from a known enum member.
Why
Generated enums come from a versioned OpenAPI spec and can lag behind the service. A
concrete case:
warehouses.list()returns the real-time warehouse typeREAL_TIME,which isn't in
EndpointInfoWarehouseType, sowarehouse_typeis dropped fromas_dict()output entirely.Fixes #1484
Behavior change
Known values still resolve to the proper enum member; absent/empty fields still return
None. This is a behavior change for callers that relied on unknown values becomingNone— flagging for maintainer input (see #1484 for the discussion).Scope
This addresses the general silent-drop (problem 2 in #1484). The missing
REAL_TIMEenum value itself (problem 1) lives in the upstream OpenAPI spec and isn't fixable in
this repo's generated
sql.py.Tests
Updated
tests/test_internal.pyto cover preservation +.valueround-trip for both_enumand_repeated_enum; added a case asserting absent fields still returnNone.tests/test_internal.pyandtests/generated/pass;ruff format/ruff checkclean.